package org.mock.service.impl;

import org.mock.entity.BaifenhuiOrderProduct;
import org.mock.mapper.BaifenhuiOrderProductMapper;
import org.mock.service.BaifenhuiOrderProductService;
import org.mock.dto.BaifenhuiOrderProductDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.mock.common.Condition;
import org.mock.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import cn.hutool.core.util.StrUtil;
import java.util.List;

/**
 * 订单商品信息 服务实现类
 *
 * @author AI
 * @since 2025-05-23
 */
@Service
@AllArgsConstructor
public class BaifenhuiOrderProductServiceImpl implements BaifenhuiOrderProductService {

    protected BaifenhuiOrderProductMapper baifenhuiOrderProductMapper;
    @Override
    public IPage<BaifenhuiOrderProduct> page(BaifenhuiOrderProductDTO dto) {
        IPage<BaifenhuiOrderProduct> page = Condition.getPage(dto);
        QueryWrapper<BaifenhuiOrderProduct> queryWrapper = Condition.getQueryWrapper(BeanCopyUtils.copy(dto, BaifenhuiOrderProduct.class));
        if (StrUtil.isNotEmpty(dto.getColumn()) && StrUtil.isNotEmpty(dto.getKeywords())) {
        queryWrapper.like(dto.getColumn(),dto.getKeywords());
        }
        if (StrUtil.isNotEmpty(dto.getOrderAsc())) {
        queryWrapper.orderByAsc(dto.getOrderAsc());
        }
        if (StrUtil.isNotEmpty(dto.getOrderDesc())) {
        queryWrapper.orderByDesc(dto.getOrderDesc());
        }
        if (dto.getStartTime() != null) {
        queryWrapper.gt("created",dto.getStartTime());
        }
        if (dto.getEndTime() != null) {
        queryWrapper.lt("created",dto.getEndTime());
        }
        return baifenhuiOrderProductMapper.selectPage(page,queryWrapper);
    }

    @Override
    public List<BaifenhuiOrderProduct> list(BaifenhuiOrderProductDTO dto) {
        QueryWrapper<BaifenhuiOrderProduct> queryWrapper = Condition.getQueryWrapper(BeanCopyUtils.copy(dto, BaifenhuiOrderProduct.class));
        if (StrUtil.isNotEmpty(dto.getColumn()) && StrUtil.isNotEmpty(dto.getKeywords())) {
        queryWrapper.like(dto.getColumn(),dto.getKeywords());
        }
        if (StrUtil.isNotEmpty(dto.getOrderAsc())) {
        queryWrapper.orderByAsc(dto.getOrderAsc());
        }
        if (StrUtil.isNotEmpty(dto.getOrderDesc())) {
        queryWrapper.orderByDesc(dto.getOrderDesc());
        }
        if (dto.getStartTime() != null) {
        queryWrapper.gt("created",dto.getStartTime());
        }
        if (dto.getEndTime() != null) {
        queryWrapper.lt("created",dto.getEndTime());
        }
        return baifenhuiOrderProductMapper.selectList(queryWrapper);
    }

    @Override
    public Integer save(BaifenhuiOrderProductDTO dto) {
        return baifenhuiOrderProductMapper.insert(BeanCopyUtils.copy(dto,BaifenhuiOrderProduct.class));
    }

    @Override
    public Integer updateById(BaifenhuiOrderProductDTO dto) {
        return baifenhuiOrderProductMapper.updateById(BeanCopyUtils.copy(dto,BaifenhuiOrderProduct.class));
    }


    @Override
    public Integer deleteLogic(List<Integer> toIntList) {
        return baifenhuiOrderProductMapper.deleteBatchIds(toIntList);
    }

    @Override
    public BaifenhuiOrderProduct getOne(BaifenhuiOrderProductDTO dto) {
        return baifenhuiOrderProductMapper.selectOne(Condition.getQueryWrapper(BeanCopyUtils.copy(dto,BaifenhuiOrderProduct.class)));
    }
}
